package f.f0.g;

import f.a0;
import f.f0.c;
import f.i;
import f.j;
import f.s;
import f.t;
import f.y;
import f.z;
import g.n;
import g.q;
import g.u;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.logging.Logger;

/* compiled from: BridgeInterceptor */
public final class a implements s {
    public final j a;

    public a(j jVar) {
        this.a = jVar;
    }

    public a0 intercept(f.s.a aVar) throws IOException {
        String str;
        Object obj;
        f fVar = (f) aVar;
        y yVar = fVar.f;
        Objects.requireNonNull(yVar);
        f.y.a aVar2 = new f.y.a(yVar);
        z zVar = yVar.d;
        String str2 = "Content-Type";
        String str3 = "Content-Length";
        if (zVar != null) {
            t contentType = zVar.contentType();
            if (contentType != null) {
                aVar2.c(str2, contentType.a);
            }
            long contentLength = zVar.contentLength();
            str = "Transfer-Encoding";
            if (contentLength != -1) {
                aVar2.c(str3, Long.toString(contentLength));
                aVar2.c.b(str);
            } else {
                aVar2.c(str, "chunked");
                aVar2.c.b(str3);
            }
        }
        String str4 = "Host";
        int i = 0;
        if (yVar.c.c(str4) == null) {
            aVar2.c(str4, c.o(yVar.a, false));
        }
        str4 = "Connection";
        if (yVar.c.c(str4) == null) {
            aVar2.c(str4, "Keep-Alive");
        }
        str4 = "Accept-Encoding";
        String str5 = "gzip";
        if (yVar.c.c(str4) == null && yVar.c.c("Range") == null) {
            aVar2.c(str4, str5);
            obj = 1;
        } else {
            obj = null;
        }
        Objects.requireNonNull((f.j.a) this.a);
        List emptyList = Collections.emptyList();
        if (!emptyList.isEmpty()) {
            StringBuilder stringBuilder = new StringBuilder();
            int size = emptyList.size();
            while (i < size) {
                if (i > 0) {
                    stringBuilder.append("; ");
                }
                i iVar = (i) emptyList.get(i);
                stringBuilder.append(iVar.a);
                stringBuilder.append('=');
                stringBuilder.append(iVar.b);
                i++;
            }
            aVar2.c("Cookie", stringBuilder.toString());
        }
        String str6 = "User-Agent";
        if (yVar.c.c(str6) == null) {
            aVar2.c(str6, "okhttp/3.12.1");
        }
        a0 b = fVar.b(aVar2.b(), fVar.b, fVar.c, fVar.d);
        e.d(this.a, yVar.a, b.f);
        f.a0.a aVar3 = new f.a0.a(b);
        aVar3.a = yVar;
        if (obj != null) {
            str = "Content-Encoding";
            String c = b.f.c(str);
            str4 = null;
            if (c == null) {
                c = null;
            }
            if (str5.equalsIgnoreCase(c) && e.b(b)) {
                n nVar = new n(b.g.q());
                f.q.a e = b.f.e();
                e.b(str);
                e.b(str3);
                List list = e.a;
                String[] strArr = (String[]) list.toArray(new String[list.size()]);
                f.q.a aVar4 = new f.q.a();
                Collections.addAll(aVar4.a, strArr);
                aVar3.f = aVar4;
                String c2 = b.f.c(str2);
                if (c2 != null) {
                    str4 = c2;
                }
                Logger logger = q.a;
                aVar3.g = new g(str4, -1, new u(nVar));
            }
        }
        return aVar3.b();
    }
}
